#include <iostream>
#include <string>
#include <signal.h>
#include <unistd.h>

void printPending(sigset_t &pending)
{
    std::cout<<"=================================================================="<<std::endl;
    for(int i = 1;i < 32;i++)
    {
        if(sigismember(&pending,i))
            std::cout<<"信号"<<i<<"以发送到位"<<std::endl;
    }
    std::cout<<"=================================================================="<<std::endl;

}

void signalHander(int signo)
{
    std::cout<<"2号信号被递达"<<std::endl;
}

int main()
{
    signal(SIGINT,signalHander);
    //屏蔽2号信号
    sigset_t block;
    sigemptyset(&block);
    sigaddset(&block,SIGINT);
    sigset_t old;
    sigprocmask(SIG_SETMASK,&block,&old);
    
    int cout = 0;
    //循环打印pendin
    while (true)
    {
        /* code */
        sigset_t pending;
        sigpending(&pending);
        printPending(pending);
        if(cout == 10)
        {
            //恢复2号信号
            sigprocmask(SIG_SETMASK,&old,nullptr);
            std::cout<<"恢复2号信号"<<std::endl;
        }
        sleep(1);
        cout++;
    }
    

    return 0;
}